package com.vise.facedemo;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;

import com.lwb.radarchart.RadarChartView;
import com.vise.facedemo.alioss.adapter.Menu_FragmentAdapter;
import com.vise.facedemo.alioss.http.API;
import com.vise.facedemo.bean.JX;
import com.vise.facedemo.utils.ASS;
import com.vise.facedemo.utils.JSONUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ResultActivity extends AppCompatActivity {

    RadarChartView.Config config;
    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.pager)
    ViewPager pager;
    @BindView(R.id.radar_chart_view)
    RadarChartView radar_chart_view;
    String s;
    @BindView(R.id.textView)
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);
        ButterKnife.bind(this);


        config = new RadarChartView.Config()
                .setMaxLevel(5)
                .setCenterPointRadius(5)
                .setChartWidget(0.8f)
                .setFillColor(0xff268415)
                .setSecondFillColor(0xffcd2626)
                .setValueLineSize(1)
                .setValuePointRadius(5)
                .setBackgroundColor(0x88985615)
                .setTextColor(0x88985615)
                .setTextSize(40)
                .setCanScroll(false)
                .setCanFling(false)
                .setValueBackgroundAlpha(0.2f)
                .setTextPosition(1.1f)
                .setPointRadius(2);

//
//
        String stringExtra = getIntent().getStringExtra("something");
        if (stringExtra.equals("err")) {
        s = ASS.readAssetsTxt(ResultActivity.this, "a");
        } else {
            s = stringExtra;
        }
        Log.e("zzz", "数据" + s);
        GsonJixi(s);

        dd();
    }

    public void GsonJixi(String st) {
        JX jx = JSONUtils.parseJSON(st, JX.class);

        JX.TizhiBean tizhi = jx.getTizhi();
        double Xueyu = tizhi.getXueyu() * 1000;
        double Yinxu = tizhi.getYinxu() * 1000;
        double Pinghe = tizhi.getPinghe() * 1000;
        double Yangxu = tizhi.getYangxu() * 1000;
        double Tebing = tizhi.getTebing() * 1000;
        double Shire = tizhi.getShire() * 1000;
        double Tanshi = tizhi.getTanshi() * 1000;
        double Qiyu = tizhi.getQiyu() * 1000;
//        Log.e("xxxx", "xx"+(int));
        radar_chart_view.insertType("血瘀质", (int) Xueyu, 1000);
        radar_chart_view.insertType("血虚质", (int) Yinxu, 1000);
        radar_chart_view.insertType("平和质", (int) Pinghe, 1000);
        radar_chart_view.insertType("阳虚质", (int) Yangxu, 1000);
        radar_chart_view.insertType("湿热质", (int) Shire, 1000);
        radar_chart_view.insertType("痰湿质", (int) Tanshi, 1000);
        radar_chart_view.insertType("气郁质", (int) Qiyu, 1000);
//        radar_chart_view.insertType("气虚质", (int)tizhi.getq()*1000, 1000);
        radar_chart_view.setConfig(config);
        //体质上那个数据
        JX.TiaoliBean tiaoli = jx.getTiaoli();
        String tizhi1 = tiaoli.getTizhi_name();
        textView.setText("体制类型:"+tizhi1);
        API.tiaoli = tiaoli;
        List<String> shiliao = tiaoli.getShiliao();
        List<JX.CharBean> charX = jx.getCharX();
        API.charX = charX;
//        List<JX.ZhengxingBean> zhengxing = jx.getZhengxing();
        API.zhengxingBeans = shiliao;
    }

    public void dd() {
        pager.setAdapter(new Menu_FragmentAdapter(getSupportFragmentManager(), ResultActivity.this));
        tabs.setTabMode(TabLayout.MODE_FIXED);
        tabs.setupWithViewPager(pager);// 将viewpager和mIndicator关联起来,必须在viewpager设置完adapter后才能调用
    }

}
